import os

import align.detect_face
import tensorflow as tf
import face_instance
import configparser


def init_mtcnn():
    '''
    创建MTCNN网络
    :return:
    '''
    pnet = None
    rnet = None
    onet = None
    with tf.Graph().as_default():
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction = 1.0)
        sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options, log_device_placement=False))
        with sess.as_default():
            pnet, rnet, onet = align.detect_face.create_mtcnn(sess, None)
    return pnet, rnet, onet

def init_face_detect():
    '''
    初始化人脸检测
    :return:
    '''
    return face_instance.get_facedetection()

def init_facenet():
    '''
    初始化facenet
    :return:
    '''
    return face_instance.get_facenet_embedding('F:/pface/trainer/model/20180408-102900/20180408-102900.pb')

def init_cfg():
    path = './config/cfg.ini'
    path = os.path.join(os.path.dirname(__file__), path)
    cfg = configparser.ConfigParser()
    cfg.read(path)
    return cfg

# 根目录
ROOT_PATH = 'F:/pface/'
#ROOT_PATH = '/pface/'

# 模型资源根路径
TRAINER_RES_ROOT_PATH = ROOT_PATH + 'trainer/'

# 级联器路径
CASCADE_PATH = TRAINER_RES_ROOT_PATH + "cascade/"

# 用户的训练模型存放路径
NPY_PATH = TRAINER_RES_ROOT_PATH + 'emb/'

#  faceNet预训练模型
MODEL_PATH = TRAINER_RES_ROOT_PATH + 'model/20180408-102900'

# 录入的人脸视频的存放路径
INPUT_TRAIN_VIDEO_PATH = ROOT_PATH + "input/train_video/"

# 录入的人脸图片的存放路径
INPUT_TRAIN_IMAGE_PATH = ROOT_PATH + "input/train_image/"

# 录入的要识别的人脸视频的存放路径
INPUT_VERIFY_VIDEO_PATH = ROOT_PATH + "input/verify_video/"

# 训练图片样本存放路径
OUTPUT_TRAIN_IMG_PATH = TRAINER_RES_ROOT_PATH + "emb_images/"

# 需要测试的图片样本存放路径
OUTPUT_VERIFY_IMG_PATH = ROOT_PATH + "output/verify_images/"

# temp path
OUTPUT_TEMP_PATH = ROOT_PATH + 'temp/'

# 初始化人脸数据库
DATASET_DICT = {}

# 初始化mtcnn人脸检测
FACE_DETECT = init_face_detect()

# 初始化facenet
FACE_NET = init_facenet()

# 人脸宽高
RESIZE_WIDTH, RESIZE_HEIGHT = 160, 160

# Mtcnn网络
PNet, RNet, ONet = init_mtcnn()

# 阈值
THRESHOLD = 0.75

CFG = init_cfg()

class MQ:
    EXCAHNGE = 'face_exchange'
    QUEUE_SHARED_FILE = 'face_shared_file'
    QUEUE_FACE_PY = 'face_python'

class TAG:
    SUFFIX_TXT = '.txt'
    SUFFIX_NPY = '.npy'

class ACTION:
   ALIGN_BUILD = '100'
